<?php
/**
 *
 * User: 梁晓伟  lxw11109@gmail.com
 * Date: 2018-08-23
 * Time: 14:16
 */

namespace App\Http\Controllers\Api\V1\Front\Mall;


use App\Http\Controllers\Controller;
use App\Models\Banner;
use App\Models\Commodity;
use App\Models\CommodityCategory;
use App\Models\CommodityComment;
use App\Models\CommoditySku;
use App\Models\Coupon;
use App\Models\UserCoupon;
use Illuminate\Http\Request;

class CommodityController extends Controller
{
    public function index(Request $request)
    {
         $data = Commodity::find(1);
         return $this->apiResponse($data);
    }

    public function show($commodityId)
    {
        $data = Commodity::find($commodityId);
        $data['skuValueList'] = CommoditySku::where('commodityId',$commodityId)->get();
        foreach ($data['skuValueList'] as &$value){
            $value->attrDesc = unserialize($value->attrDesc);
        }
        return $this->apiResponse($data);
    }


    public function commodityComment()
    {
        $commodityId = $_GET['commodityId'];
        $comment = CommodityComment::where('commodityId',$commodityId)->where('status',1)->paginate()->toArray();

        $result['commentList'] = $comment['data'];
        $result['totalNum'] = $comment['total'];

        return $this->apiResponse($result);

    }
}